package com.doit.demo04;

import com.doit.demo03.Person;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class test04 {
    public static void main(String[] args) {
        Stream<String> stream = Stream.of("金子", "银子", "筒子", "一饼");
        stream.map(s->new Person(s)).forEach(s-> System.out.println(s));
        //map的作用就是将stream数据转换类型
        Stream<String> stringStream = Stream.of("12", "32", "4");
        stringStream.map(s->Integer.parseInt(s)).sorted((Integer i,Integer j)->{ return i-j;}).forEach(s-> System.out.println(s));

        Stream<String> s = Stream.of("史丹利", "复合肥");
        //Stream 转 集合
//        ArrayList<String> list1 = s.collect(Collectors.toCollection(ArrayList::new));
//        HashSet<String> hashset1 = s.collect(Collectors.toCollection(HashSet::new));
//        List<String> collect = s.collect(Collectors.toList());

        //Stream 转 数组
//        Object[] objects = s.toArray();
        String[] strings = s.toArray(String[]::new);
        System.out.println(strings[1]);


    }
}
